
package cn.gz3c.uitest.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.MotionEvent;

import com.huawei.hms.audioeditor.sdk.bean.HAEAudioVolumeObject;
import com.huawei.hms.audioeditor.sdk.util.SmartLog;
import com.huawei.hms.audioeditor.ui.common.utils.d;
import com.huawei.hms.audioeditor.ui.p.s;

import java.util.List;

import cn.gz3c.uitest.Util;
import cn.gz3c.uitest.viewmodel.EditPreviewViewModel;


@SuppressLint("ViewConstructor")
public class WaveTrackWithFootPrintsView extends BaseTrackView {
    private Paint I;
    private Paint J;
    private Paint K;
    private int L;
    private long M;
    private long N;
    private int O;
    private int P;
    private long Q;
    private RectF R;
    private final List<s> S;
    private final List<HAEAudioVolumeObject> T;
    private final boolean[] U;
    private float V;
    private int W;

    public WaveTrackWithFootPrintsView(Activity var1, EditPreviewViewModel var2, List<com.huawei.hms.audioeditor.ui.p.s> s, List<HAEAudioVolumeObject> t, boolean[] u) {
        super(var1, var2);
        S = s;
        T = t;
        U = u;
    }

    private float a(HAEAudioVolumeObject var1) {
        WaveTrackWithFootPrintsView var10000 = this;
        float var2 = (float) (var1.getMaxValue() - '썐');
        int var3 = var1.getVolume();
        return (float) (Math.abs(var10000.getMeasuredHeight() - Util.dip2px(16.0F)) / 2 * var3) / var2;
    }

    static {
        WaveTrackWithFootPrintsView.class.getSimpleName();
    }

    protected void onMeasure(int var1, int var2) {
        super.onMeasure(var1, var2);
        this.setMeasuredDimension((int) (this.j() + (double) this.L), Util.dip2px(48.0F));
    }

    public double j() {
        return (double) this.i() / d.a(super.l) * super.m - super.n - super.o - (double) Util.dip2px(2.0F);
    }

    @SuppressLint({"DrawAllocation"})
    protected void onDraw(Canvas var1) {
        this.a(super.g);
        RectF var2;

        float var10006 = (float) super.a;
        float var10007 = (float) Util.dip2px(3.0F);
        double var3 = (double) super.a;
        RectF var10004 = var2 = new RectF(var10006, var10007, (float) (this.j() + var3), (float) Util.dip2px(30.0F));
        this.V = (var10004.right - var2.left) / (float) super.r;
        super.onDraw(var1);
        SmartLog.i("mCurrentTime", super.g + "");
        int var4;
        int var5;
        int var6;
        RectF var8;
        float var9;
        float var10;
        double var11;
        float var12;
        float var10000;
        if (!((double) Math.abs(super.g - this.Q) < d.a(super.l) * 3.0D) || this.Q == 0L) {

            if ((var4 = super.a) + (var5 = this.O) - 1000 > var4) {
                var9 = (float) (var4 + var5 - 1000);
            } else {
                var9 = (float) var4;
            }

            var10 = (float) Util.dip2px(3.0F);
            var10000 = (float) (this.P + (var6 = super.a) + 1000);
            var11 = (double) var6;
            if (var10000 > (float) (this.j() + var11)) {
                var11 = (double) super.a;
                var12 = (float) (this.j() + var11);
            } else {
                var12 = (float) (this.P + super.a + 1000);
            }
            var8 = new RectF(var9, var10, var12, (float) Util.dip2px(48.0F));
            this.R = var8;
            this.Q = super.g;
        }

        if (this.R == null) {

            if ((var4 = super.a) + (var5 = this.O) - 1000 > var4) {
                var9 = (float) (var4 + var5 - 1000);
            } else {
                var9 = (float) var4;
            }

            var10 = (float) Util.dip2px(3.0F);
            var10000 = (float) (this.P + (var6 = super.a) + 1000);
            var11 = (double) var6;
            if (var10000 > (float) (this.j() + var11)) {
                var11 = (double) super.a;
                var12 = (float) (this.j() + var11);
            } else {
                var12 = (float) (this.P + super.a + 1000);
            }

            var8 = new RectF(var9, var10, var12, (float) Util.dip2px(48.0F));
            this.R = var8;
        }

        this.b(var1, this.R);
        this.a(var1, var2);
    }

    protected void b(Canvas var1, RectF var2) {
        float var7 = var2.centerY();

        for (HAEAudioVolumeObject haeAudioVolumeObject : this.T) {
            HAEAudioVolumeObject var4;
            HAEAudioVolumeObject var10001 = var4 = haeAudioVolumeObject;
            float var5 = (float) this.W;
            float var6 = (float) (var10001.getTime() - this.M) * this.V + var5;
            float var10002 = var7 - this.a(var4);
            var5 = (float) this.W;
            var1.drawLine(var6, var10002, (float) (var4.getTime() - this.M) * this.V + var5, var7 + this.a(var4), this.I);
        }

    }

    protected void a(Canvas var1, RectF var2) {
        float var5 = (float) Util.dip2px(38.0F);

        for (int var3 = 0; var3 < this.S.size(); ++var3) {
            float var4;
            if ((float) this.b() - this.a(((s) this.S.get(var3)).a() + (float) this.a().getStartTime()) < 10.0F && (float) this.b() - this.a(((s) this.S.get(var3)).a() + (float) this.a().getStartTime()) > -10.0F) {
                var4 = (float) super.a;
                var1.drawPoint(this.a(((s) this.S.get(var3)).a()) + var4, var5, this.K);
            } else {
                var4 = (float) super.a;
                var1.drawPoint(this.a(((s) this.S.get(var3)).a()) + var4, var5, this.J);
            }
        }

    }

    void a(long var1, int var3) {
        if (var1 != 0L) {
            StringBuilder stringBuilder = new StringBuilder();
            SmartLog.i("handleCutEvent", stringBuilder.append(var1).append("").toString());
            this.n().a(this.a(), var1, var3);
        }
    }

    public void a(long var1) {
        if (this.a() != null) {
            double var3;
            double var5;
            double var10000 = var3 = (var5 = (double) (super.g - this.a().getStartTime())) - d.a(super.l) * 5.0D;
            var5 += d.a(super.l) * 5.0D;
            if (var10000 < 0.0D) {
                var3 = 0.0D;
            }

            if (var5 > (double) this.a().getDuration()) {
                var5 = (double) this.a().getDuration();
            }

            this.O = (int) (this.j() * var3 / (double) this.a().getDuration());
            this.P = (int) (this.j() * var5 / (double) this.a().getDuration());
            SmartLog.i("wwyWaveView1", com.huawei.hms.audioeditor.ui.p.a.a("handleCurrentTimeChange: currentTime:").append(super.g).append("|index:").append(this.O).append("|endIndex:").append(this.P).append("-endIndex - index").append(this.P - this.O).toString());
        }

    }

    public float a(float var1) {
        return this.V * var1;
    }

    public void a(int var1, int var2, MotionEvent var3) {
        SmartLog.i("handleCutEvent", var1 + "");
        if (var1 != 0 && (var1 <= 0 || !(this.j() - (double) var1 <= this.h())) && (var1 >= 0 || !(this.j() - (double) var1 >= this.g()))) {
            double var6;
            double var4 = (var6 = (double) var1) / this.e();
            long var7 = (long) (d.a(this.d()) * var4);
            if (var2 == 0) {
                if (var7 < 0L && this.M + var7 <= 0L) {
                    return;
                }

                super.n += var6;
                super.D = (long) Util.multiply10(d.a(super.l), Util.divide10(super.n, super.m));
            } else {
                if (var7 < 0L && this.N + var7 <= 0L) {
                    return;
                }

                super.o += var6;
                super.D = (long) com.huawei.hms.audioeditor.ui.common.utils.a.d(d.a(super.l), com.huawei.hms.audioeditor.ui.common.utils.a.b(super.o, super.m));
            }

            this.r();
            this.post(this::invalidate);
        }
    }

    public void b(double var1) {
        super.z = Util.toScale(var1, 0);
        this.postInvalidate();
        this.U[0] = false;
    }
}
